package it.ap.sa.core.dao.util.serializer;

import java.io.IOException;
import java.util.List;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

public class ArraySerializer <T> extends JsonSerializer<List<T>> {

    @SuppressWarnings("unused")
	private final Class<T> clazz;

    public ArraySerializer(Class<T> clazz) {
        this.clazz = clazz;
    }
	@Override
	public void serialize(List<T> listObject, JsonGenerator jgen, SerializerProvider serializers) throws IOException, JsonProcessingException {		
		
		jgen.writeStartObject();
		Integer index = 0;
		for(T object:listObject)
		{
			jgen.writeObjectField(index.toString(), object);
			index++;
		}
		jgen.writeEndObject();
		
	}
}